/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"AD7090F2-FFA0-4A99-84CB-00E5940C570D"}
 */
function buscarDocumento(event) {
	if (recep_cabecera_to_recep_detalle_ind.getSize() > 0)
	{
		recep_cabecera_to_recep_detalle_ind.deleteAllRecords()
	}
	var $win = application.createWindow('BUSCAREM',JSWindow.MODAL_DIALOG)
	$win.title = 'Buscar Remito'
	forms.recepciones_int_carga_remito_ind.controller.show($win)
}

/**
 * Callback method for when form is shown.
 *
 * @param {Boolean} [firstShow] form is shown first time after load
 * @param {JSEvent} [event] the event that triggered the action
 *
 * @properties={typeid:24,uuid:"C6812609-5C49-4F93-8398-EFD5B09124D2"}
 */
function onShow(firstShow, event) {

	databaseManager.setAutoSave(false)
	controller.newRecord()
	fecha		= application.getServerTimeStamp()
	//es_preview 	= 0
	tipo		= 2
}

/**
 * @properties={typeid:24,uuid:"41F73904-DCC0-4469-8D3E-4D17A078FDFB"}
 */
function confirmar() {

	if (nro_remito == null)
	{
		globals.DIALOGS.showInfoDialog('Aviso','Por favor indique un remito para seguir','OK')  //23/01/2014
		return
	}
	
	recepciones_to_numeracion_pr.ultimo_numero++
	nro_recep = recepciones_to_numeracion_pr.ultimo_numero
	
	if (databaseManager.saveData())
	{
		if (globals.DIALOGS.showQuestionDialog('Imprime','Recepcion Nº '+ nro_recep+'.¿Desea imprimirla?','Si','No') == 'Si')
		{
			//es_preview = 1
			//forms.recepciones_cab_imp_ind.buscarTotalesMadera()
			forms.recepciones_cab_imp_ind.controller.loadRecords(recep_cabecera_id)
			forms.recepciones_cab_imp_ind.controller.showPrintPreview()
		}
		else
			onShow()
	}
	else
		globals.DIALOGS.showInfoDialog('Error','Ocurrio un error en la grabacion','OK') // 23/01/2014
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"4CE3972C-6EA3-4CD6-AC12-C8529944C5FC"}
 */
function cancelar(event) {
	databaseManager.revertEditedRecords()
	onShow()
}

/**
 * @param {JSRecord<db:/infocom/rem_cabecera>} $rem
 * @param {JSFoundset<db:/infocom/rem_detalle>} $dtls
 * 
 * @properties={typeid:24,uuid:"F49C9D12-7950-42BE-AEBB-CA4E85605067"}
 */
function cargaDatos($rem,$dtls)
{
	deposito			= $rem.deposito_destino
	deposito_origen		= $rem.deposito
	nro_remito			= $rem.letra + '-' + utils.numberFormat($rem.sucursal,'0000')+ '-' + utils.numberFormat($rem.nro_remito,'00000000')
	razon_social		= $rem.rem_cabecera_to_depositos.descripcion
	recep_estado		= 1
	sucursal			= globals.gSucursal
	letra				= 'X'
	
	/** @type {JSFoundSet<db:/infocom/recep_detalle>}*/
	var $rng = recep_cabecera_to_recep_detalle_ind
	for (var i = 1 ; i <= $dtls.getSize() ; i++)
	{
		var $dtl = $dtls.getRecord(i)
		
		$rng.newRecord()
		
		$rng.cantidad		= $dtl.cantidad
		$rng.producto_id	= $dtl.producto_id
		$rng.rem_detalle_id = $dtl.rem_detalle_id
	}
}
